package aps

import grails.converters.JSON
import org.apache.commons.logging.LogFactory

class WeldingDrawingController {

    private final static logger = LogFactory.getLog(this)
    /**
     * 焊线图请求文件全名
     * @return
     */
    def index() {
        def htmlfileName = params.htmlfileName ?: ''

        def DiagramVersion = params.DiagramVersion ?: ''

//        htmlfileName = htmlfileName + '-' + DiagramVersion
        print htmlfileName

        def dir = new File("G:\\")
        def retureFileName
        def returnFilePath
        def path
        def haveFile = false   //文件是否存在
        def msg = [:]

        dir.eachFileRecurse { file ->

            def severFileName = file.name
            def severFilePath = file.path

            //匹配文件
            if (severFileName.contains(htmlfileName) == true) {

                retureFileName = severFileName
                print retureFileName
                print severFilePath
                haveFile = true
                print haveFile
                //获取目录
                returnFilePath = severFilePath.split("\\\\")

                if (returnFilePath.length > 2) {
                    path = returnFilePath[1]
                }
                //获取文件类型
                def length = retureFileName.length()
                def ext = retureFileName.substring(length - 3, length);

                msg.returnFilePath = path
                msg.retureFileName = retureFileName
                msg.ext = ext
                msg.haveFile = haveFile
            } else {
                msg.haveFile = haveFile
            }
        }

        print haveFile

        print msg as JSON
        logger.info(msg as JSON)
        render msg as JSON


    }
}